package com.xiao.gulimall.product.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.common.utils.R;
import com.xiao.gulimall.product.controller.CategoryController;
import com.xiao.gulimall.product.dao.CategoryDao;
import com.xiao.gulimall.product.entity.CategoryEntity;
import com.xiao.gulimall.product.service.CategoryService;
import com.xiao.gulimall.product.vo.Catalog2Vo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class ProductWeb {
    @Autowired
    CategoryService categoryService;


    @RequestMapping(value = {"/", "/index.html"})
    public String producthtml(Model model) {
        System.out.println("11");
        List<CategoryEntity> categorylist = categoryService.list(new QueryWrapper<CategoryEntity>().eq("parent_cid", 0));
        model.addAttribute("list", categorylist);
        return "index";
    }

    public R treelist() {
        return categoryService.treelist();
    }
    @ResponseBody
    @GetMapping("index/json/catalog")
    public HashMap<String,List<Catalog2Vo>> cataloglist(){
     //   HashMap<String, List<Catalog2Vo>> cataloglist = new HashMap<String, List<Catalog2Vo>>();
        //首先查询一级菜单
        return categoryService.catelogredisson();
    }



}
